require 'rubygems'
require 'mp3info'

class Mp3Parser
  attr_accessor :lyrics

  def initialize
    @lyrics= []
  end

  def parse filename
    if File.directory?(filename)
      Dir.foreach(filename) do |file2|
        unless ['.','..'].include?(file2)
          f= File.join(filename,file2)
          parse f
        end
      end
      return
    end
    
    ext=File.extname(filename)
    if (ext=='.mp3')
      Mp3Info.open(filename) do |mp3|
        if mp3.tag.title
          lyric=Lyric.new(:artist=>mp3.tag.artist, :album=>mp3.tag.album, :title=>mp3.tag.title,
            :tracknum=>mp3.tag.tracknum, :mp3_filename=>filename)
          @lyrics << lyric
          puts "Added : #{lyric.to_s}"  
        end
      end
    end
    
  end

end

